package com.internetCafes.spms.web.sys.controller;

import com.internetCafes.spms.core.utils.PageUtils;
import com.internetCafes.spms.core.utils.Query;
import com.internetCafes.spms.core.utils.R;
import com.internetCafes.spms.web.sys.model.AreaInfo;
import com.internetCafes.spms.web.sys.service.AreaInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 全国行政区划表
 * 
 * @author Sunny
 * @email rekeeper2011@hotmail.com
 * @date 2018-01-26 14:19:59
 */
@RestController
@RequestMapping("/sys/areainfo")
public class AreaInfoController {
	@Autowired
	private AreaInfoService areaInfoService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("sys:areainfo:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<AreaInfo> areaInfoList = areaInfoService.queryList(query);
		int total = areaInfoService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(areaInfoList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("sys:areainfo:info")
	public R info(@PathVariable("id") Long id){
		AreaInfo areaInfo = areaInfoService.queryObject(id);
		
		return R.ok().put("areaInfo", areaInfo);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("sys:areainfo:save")
	public R save(@RequestBody AreaInfo areaInfo){
		areaInfoService.save(areaInfo);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("sys:areainfo:update")
	public R update(@RequestBody AreaInfo areaInfo){
		areaInfoService.update(areaInfo);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("sys:areainfo:delete")
	public R delete(@RequestBody Long[] ids){
		areaInfoService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
